<?php
/**
 * Created by PhpStorm.
 * ajax类
 * User: 李洋波
 * Date: 2016/9/13
 * Time: 9:37
 */

class ajax_two extends CI_Controller{
    function __construct()
    {
        parent::__construct();
        ob_end_clean();
        $this->load->model('ajax_model/ajax_two_model','ajax');
    }

    /**
     * 扣除客户金额
     */
    public function DeductionBalance(){
        $gp=gp();
        //获取客户信息
        if($gp['money']>0) {
            $clineInfo = $this->ajax->GetClineInfo($gp['clineId']);
            //汇率转换
            if (strcasecmp($gp['currency'], $clineInfo['CurrencyIsoCode'])) {
                $gp['money'] = currency_service($gp['currency'], $clineInfo['CurrencyIsoCode'], $gp['money']);
            }
            if($gp['money']) {
                //资金记录数组
                $dataRecord = array(
                    'customers_id' => $gp['clineId'],
                    'money' => -$gp['money'],
                    'orderId' => $gp['orderId'],
                    'currency' => $clineInfo['CurrencyIsoCode'],
                    'time' => time(),
                    'add_name' => $gp['name']
                );
                //判断余额是否透支完毕
                $facilityExtent = $clineInfo['facilityExtent'] + ($clineInfo['Balances'] - $gp['money']);
                if ($facilityExtent >= 0) {
                    //扣除余额
                    $result = $this->ajax->DeductionMoney($gp['clineId'], 'Balances', $gp['money']);
                    if ($result) {
                        //添加存款记录
                        $this->ajax->AddMoneyRecord($dataRecord);
                        //更新扣款状态
                        $this->ajax->UpdateBatchOrder($gp['id'], array('is_charge' => 1));
                        echo '1';
                    }
                } else {
                    echo '2';
                }
            }else{
                echo '4';
            }
        }else{
            echo '3';
        }
    }

    /**
     *获取产品故障信息
     */
    public function GetProductFaultInfo(){
        $gp=gp();
        $faultInfo=$this->ajax->GetFaultInfo($gp['id']);
        echo json_encode($faultInfo);
    }

    /**
     * 获取产品故障
     */
    public function GetProductFault(){
        $gp=gp();
        $faultInfo=$this->ajax->GetFault($gp['typeId']);
        echo json_encode($faultInfo);
    }
    /**
     * 获取产品附件信息
     */
    public function GetProductAccessoryInfo(){
        $gp=gp();
        $accessoryList=$this->ajax->GetAccessoryInfo($gp['id']);
        echo json_encode($accessoryList);
    }

    /**
     * 获取产品附件
     */
    public function GetProductAccessory(){
        $gp=gp();
        $faultList=$this->ajax->GetAccessory($gp['typeId']);
        echo json_encode($faultList);
    }

    /**
     * 名称验证
     */
    public function NameVerify(){
        $gp=gp();
        $data=$this->ajax->NameVerify($gp['table'],$gp['category'],trim($gp['name_ch']),trim($gp['name_en']));
        if($data==''){
            echo '1';
        }else{
            echo '2';
        }
    }

    /**
     * 获取角色信息
     */
    public function GetRoleInfo(){
        $gp=gp();
        $data=$this->ajax->GetRoleInfo($gp['id']);
        echo json_encode($data);
    }

    /**
     * 获取权限信息
     */
    public function GetPermissionInfo(){
        $gp=gp();
        $data=$this->ajax->GetPermissionInfo($gp['id']);
        echo json_encode($data);
    }

    /**
     * 获取订单信息
     */
    public function GetOrderInfo(){
        $gp=gp();
        $data=$this->ajax->GetOrderInfo($gp['order_num']);
        echo json_encode($data);
    }
    public function serviceQcPrint(){
        $gp=gp();
        $this->load->library('barcode');
        $data=array(
            'imei'=>$this->barcode->getBarcodeHTML($gp['imei'], "C128"),
            'imeitwo'=>$this->barcode->getBarcodeHTML($gp['imeitwo'], "C128"),
            'imeithree'=>$this->barcode->getBarcodeHTML($gp['imeithree'], "C128"),
            'sn'=>$this->barcode->getBarcodeHTML($gp['sn'], "C128"),
            'cmda'=>$this->barcode->getBarcodeHTML($gp['cmda'], "C128"),
        );
        echo json_encode($data);
    }
}